package com.gopay.cron.service.cloud.gen.bean;

import com.gopay.cron.web.vo.CloudAccountStatementVO;

/**
 * Created by Johnson on 2017/3/1.
 */
public class RefundFileInfo {

    public static final String fileName = "02";
    public static final String fileFtpName = "收款退款类";

    public static final String txtFirstLine = "商户退款订单号\t国付宝账户号\t原商户订单号\t退款类型\t退款请求时间\t清算时间\t退款金额\t原交易金额\t已退手续费\t出账金额\t原支付渠道";
    public static final String csvFirstLine = "\"商户退款订单号\",\"国付宝账户号\",\"原商户订单号\",\"退款类型\",\"退款请求时间\",\"清算时间\",\"退款金额\",\"原交易金额\",\"已退手续费\",\"出账金额\",\"原支付渠道\"";

    private static final String csvFtpFirstLine = "\"商户账户\",\"退款总笔数\",\"退款总金额\",\"退款总手续费\"";
    private static final String csvFtpSecondLine = "\"国付宝交易号\",\"商户退款订单号\",\"原国付宝交易号\",\"原商户订单号\",\"交易类型\",\"退款时间\",\"完成时间\",\"退款金额\",\"原交易金额\",\"退款手续费\"";

    private StringBuilder txtLineContent = new StringBuilder();
    private StringBuilder csvLineContent = new StringBuilder();
    private StringBuilder csvFtpFirstLineContent = new StringBuilder();
    private StringBuilder csvFtpSecondLineContent = new StringBuilder();

    public void addRefundFileLine(CloudAccountStatementVO vo) {
        addTxtFileLine(vo);
        addCsvFileLine(vo);
    }


    public void addTxtFileLine(CloudAccountStatementVO vo) {
        txtLineContent.append(vo.getMerOrderId()).append("\t")
                .append(vo.getGopayAcct()).append("\t")
                .append(vo.getOrigMerOrderId()).append("\t")
                .append(vo.getGopayIntTxnCd()).append("\t")
                .append(vo.getReqTime()).append("\t")
                .append(vo.getTranFinishTime()).append("\t")
                .append(vo.getMerTxnAmt()).append("\t")
                .append(vo.getOrigMerTxnAmt()).append("\t")
                .append(vo.getRefundFeeAmt()).append("\t")
                .append(vo.getRealAmt()).append("\t")
                .append(vo.getPayChannel())
                .append("\r\n");
    }

    public void addCsvFileLine(CloudAccountStatementVO vo) {
        csvLineContent.append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getOrigMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrigMerTxnAmt()).append("\",")
                .append("\"").append(vo.getRefundFeeAmt()).append("\",")
                .append("\"").append(vo.getRealAmt()).append("\",")
                .append("\"").append(vo.getPayChannel()).append("\"")
                .append("\r\n");
    }

    public String getTxtContent() {
        StringBuilder sb = new StringBuilder(RefundFileInfo.txtFirstLine);
        sb.append("\r\n").append(txtLineContent.toString());
        return sb.toString();
    }

    public String getCsvContent() {
        StringBuilder sb = new StringBuilder(RefundFileInfo.csvFirstLine);
        sb.append("\r\n").append(csvLineContent.toString());
        return sb.toString();
    }


    public String getFtpCsvContent() {
        StringBuilder sb = new StringBuilder(RefundFileInfo.csvFtpFirstLine);
        sb.append("\r\n").append(csvFtpFirstLineContent.toString());
        sb.append(RefundFileInfo.csvFtpSecondLine);
        sb.append("\r\n").append(csvFtpSecondLineContent.toString());
        return sb.toString();
    }

    public void addFtpFirstRefundFileLine(CloudAccountStatementVO vo) {
        addFtpFirstCsvFileLine(vo);
    }

    private void addFtpFirstCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpFirstLineContent.append("\"").append(vo.getGopayAcct()).append("\",")
                .append("\"").append(vo.getTotalCount()).append("\",")
                .append("\"").append(vo.getTotalTxnAmt()).append("\",")
                .append("\"").append(vo.getTotalFeeAmt()).append("\"")
                .append("\r\n");
    }

    public void addFtpSecondRefundFileLine(CloudAccountStatementVO vo) {
        addFtpSecondCsvFileLine(vo);
    }

    private void addFtpSecondCsvFileLine(CloudAccountStatementVO vo) {
        csvFtpSecondLineContent.append("\"").append(vo.getGopayOrderId()).append("\",")
                .append("\"").append(vo.getMerOrderId()).append("\",")
                .append("\"").append(vo.getOrigGopayOrderId()).append("\",")
                .append("\"").append(vo.getOrigMerOrderId()).append("\",")
                .append("\"").append(vo.getGopayIntTxnCd()).append("\",")
                .append("\"").append(vo.getReqTime()).append("\",")
                .append("\"").append(vo.getTranFinishTime()).append("\",")
                .append("\"").append(vo.getMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrigMerTxnAmt()).append("\",")
                .append("\"").append(vo.getOrderFeeAmt()).append("\"")
                .append("\r\n");
    }

}
